package schoolword;

import java.io.*;

public class Text2 {
    public static void main(String[] args) throws IOException {
        //把两个文件 用字符流  合并成一个文件
        File file1 = new File("D:\\wenjianjia\\text1.txt");
        File file2 = new File("D:\\wenjianjia\\text2.txt");
        File file3 = new File("D:\\wenjianjia\\text4.txt");  //合并后的文件

        //全部写入  text3
        FileReader fr1 = new FileReader(file1);
        FileReader fr2 = new FileReader(file2);
        FileWriter fw = new FileWriter(file3);

        try {
            int i = fr1.read();
            while (i != -1) {
                fw.write(i);
                i = fr1.read();
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
            fr1.close();
        }

        System.out.println("----------");
        //读第二个文件
        int j = fr2.read();
        while (j != -1) {
            fw.write(j);
            j = fr2.read();
        }
        fr2.close();
        fw.close();
    }
}
